package ViewPagerLoadData;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.qf.bean.NewHome;
import com.qf.bean.NewHomeAll;
import com.qf.bean.ViewPagerEntity;

public class ParserViewPagerData
{
	public static List<ViewPagerEntity> parseData(String json)
	{
		try
		{
			JSONObject jsonObject = new JSONObject(json);
			JSONArray array = jsonObject.getJSONArray("data");
			Log.i("info", "jdfskljfksjfwie935803968");
			List<ViewPagerEntity> datas = JSON.parseArray(array.toString(),
					ViewPagerEntity.class);
			return datas;
		}
		catch (JSONException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}

	public static List<NewHomeAll> parseHomeData(String json)
	{

		try
		{
			// Log.i("info", "下载完成的数据为:" + json);
			JSONObject object = new JSONObject(json);
			NewHomeAll newHomeAll;
			JSONArray array_data = object.getJSONArray("data");
			// Log.i("info", "data的数据为:" + array_data);

			List<NewHomeAll> allList = new ArrayList<NewHomeAll>();
			for (int i = 0; i < array_data.length(); i++)
			{
				JSONObject obj1 = array_data.getJSONObject(i);
				newHomeAll = new NewHomeAll();

				newHomeAll.setGc_id(obj1.getString("gc_id"));
				newHomeAll.setGc_name(obj1.getString("gc_name"));
				newHomeAll.setGc_parent_id(obj1.getString("gc_parent_id"));
				newHomeAll.setPic_path(obj1.getString("pic_path"));

				JSONArray subList_array = obj1.getJSONArray("subList");
				// Log.i("info", "subList的数据为:" + subList_array);

				NewHome newHome;
				List<NewHome> dHomes = new ArrayList<NewHome>();
				for (int j = 0; j < subList_array.length(); j++)
				{

					newHome = new NewHome();
					JSONObject obj2 = subList_array.getJSONObject(j);
					newHome.setGc_name(obj2.getString("gc_name"));
					dHomes.add(newHome);
				}

				newHomeAll.setSubList(dHomes);
				allList.add(newHomeAll);

			}
			// Log.i("info", "接卸完成的数据为:" + allList);
			return allList;
		}
		catch (JSONException e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
